﻿using UnityEngine;
using System.Collections;

public class UIPressCharImage : uiBaseButton {
	
	public int charOrder;
	
	Color reserveColor;
	bool bGlow;
	public bool bForSkillTarget;
	UISprite sprite;
	public GameObject hpDetail;

	// Use this for initialization
	void Start () {
		sprite = GetComponent<UISprite>();
		reserveColor = sprite.color;
	}

	void OnPress (bool isDown)
	{
		CameraControl cc = Camera.main.gameObject.GetComponent<CameraControl>();
		if(isDown)
		{
			cc.PressedUIButton(true);
			UIManager.Instance.CallDelayedPressUp();
		}

		if(false)//bForSkillTarget && SkillManager.Instance.bWaitSelectTarget)
		{
			//if(isDown)
			//	SkillManager.Instance.CastSkillToTarget( HudManager.Instance.charOrderSidDic[charOrder] );
		}
		else
		{
			if(isDown)
			{
				int sid = HudManager.Instance.charOrderSidDic[charOrder];

				bool isBotToPC = StageManagerWrapper.GetBoardPerson(sid).ChangeBotToPC();
				if(isBotToPC)
					return;

				if(!cc.isPreventChangeFocus)
				{
					cc.ResetZoom();
					cc.SetCameraFocus( StageManagerWrapper.GetBoardPerson(sid).transform );
				}



				//StopCoroutine("CoPressDown");
				//StartCoroutine("CoPressDown");
			}
			else
			{
				//StopCoroutine("CoPressDown");
				//hpDetail.SetActive(false);
			}
		}
	}

	IEnumerator CoPressDown()
	{
		float timePressDown = 0.0f;
		while(timePressDown< 0.5f)
		{
			timePressDown += Time.deltaTime;
			yield return null;
		}

		hpDetail.SetActive(true);
		int sid = HudManager.Instance.charOrderSidDic[charOrder];
		hpDetail.GetComponent<UILabel>().text = "HP "+ HudManager.Instance.CurHP(sid);
	}
	
//	public void Glow(bool bActive)
//	{
//		if(bActive) {
//			bGlow = true;
//			StartCoroutine( GlowEffect(0.5f, 1.5f) );
//		}
//		else
//			bGlow = false;
//			
//	}
//	
//	IEnumerator GlowEffect(float bound, float speed)
//	{
//		
//		float alpha = 1.0f;
//		float alpha_delta = -speed;
//		float sumTime = 0.0f;
//		while(bGlow )
//		{
//			sumTime += Time.deltaTime;
//			alpha += alpha_delta * Time.deltaTime;
//			if(alpha <bound) {
//				alpha = bound;
//				alpha_delta = -alpha_delta;
//			}
//			if(alpha >1.0f) {
//				alpha = 1.0f;
//				alpha_delta = -alpha_delta;
//			}
//			sprite.color = new Color(reserveColor.r*alpha, reserveColor.g*alpha, reserveColor.b*alpha, reserveColor.a);
//			yield return null;
//		}
//		sprite.color = reserveColor;
//	}	

}
